package com.bhkj.websocketlibrary.ws;

import com.blankj.utilcode.util.ObjectUtils;

public class WsConfig {
    /**
     * websocket访问地址
     */
    private String url;
    /**
     * 传递鉴权参数
     */
    private String query;

    /**
     * 登录推送消息接收设备类型 窗口屏或者是评价器
     */
    private String loginType;

    /**
     * 登出类型
     */
    private String logoutType;

    /**
     * 叫号
     */
//    private String takeNum;

    /**
     * 叫上一个号
     */
//    private String preNum;

    /**
     * 发起评价
     */
//    private String evaluate;

    private String otherType;

    /**
     * 窗口状态
     */
    private String windowStatusType;

    /**
     * websocket连接
     */
    private int port;
    /**
     * 断线重连的次数
     */
    private int retryCount;

    /**
     * 断线重连的间隔时间
     */
    private String retryTimeGap;

    private WsConfig() {

    }

    private static class Holder {
        private static WsConfig INSTANCE = new WsConfig();
    }

    public static WsConfig getInstance() {
        return Holder.INSTANCE;
    }

    public WsConfig setUrl(String url) {
        this.url = url;
        return this;
    }

    public WsConfig setPort(int port) {
        this.port = port;
        return this;
    }

    public WsConfig setRetryCount(int retryCount) {
        this.retryCount = retryCount;
        return this;
    }

    public WsConfig setRetryTimeGap(String retryTimeGap) {
        this.retryTimeGap = retryTimeGap;
        return this;
    }

    public int getRetryCount() {
        return retryCount;
    }

    public String getRetryTimeGap() {
        return retryTimeGap;
    }

    public WsConfig setQuery(String query) {
        this.query = query;
        return this;
    }

    public String getQuery() {
        return query;
    }

    public String getLoginType() {
        if (ObjectUtils.isEmpty(loginType)) {
            throw new RuntimeException("login type must be not empty,please set!");
        }
        return loginType;
    }

    public WsConfig setLoginType(String loginType) {
        this.loginType = loginType;
        return this;
    }

    public String getUrl() {
        if (ObjectUtils.isEmpty(url)) {
            throw new RuntimeException("url must not null");
        }
        if (url.contains("http")) {
            return url;
        }

        if (ObjectUtils.equals(0, port)) {
            throw new RuntimeException("port must be set");
        }
        return "ws://" + url + ":" + port;
    }

    public String getLogoutType() {
        if (ObjectUtils.isEmpty(logoutType)) {
            throw new RuntimeException("logout type must be not empty,please set!");
        }
        return logoutType;
    }

    public WsConfig setLogoutType(String logoutType) {
        this.logoutType = logoutType;
        return this;
    }

//    public String getTakeNum() {
//        return takeNum;
//    }
//
//    public void setTakeNum(String takeNum) {
//        this.takeNum = takeNum;
//    }
//
//    public String getPreNum() {
//        return preNum;
//    }
//
//    public void setPreNum(String preNum) {
//        this.preNum = preNum;
//    }
//
//    public String getEvaluate() {
//        return evaluate;
//    }
//
//    public void setEvaluate(String evaluate) {
//        this.evaluate = evaluate;
//    }


    public WsConfig setOtherType(String otherType) {
        this.otherType = otherType;
        return this;
    }

    public String getOtherType() {
        return otherType;
    }

    public String getWindowStatusType() {
        return windowStatusType;
    }

    public WsConfig setWindowStatusType(String windowStatusType) {
        this.windowStatusType = windowStatusType;
        return this;
    }
}
